﻿using System;

namespace lwzlz.Web.Extension.DateTimes
{
    public class ConvertData
    {
        public string ConvertDateToAge(string date)
        {
            if (string.IsNullOrWhiteSpace(date))
            {
                return "未知";
            }
            else
            {
                try
                {
                    var now = DateTime.Now;
                    var birthDate = DateTime.Parse(date);
                    int age = now.Year - birthDate.Year;
                    if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age--;
                    return age.ToString();
                }
                catch (Exception)
                {
                    return "未知";

                }

            }
        }
    }
}